package com.tedu.controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.tedu.element.ElementObj;
import com.tedu.element.player.Player;
import com.tedu.manager.ElementManager;
import com.tedu.manager.GameElement;

/**
 * 监听类
 * 负责记录当前有哪些键被按下
 */
public class GameListener implements KeyListener {
    private static final Set<Integer> pressedKeys = Collections.synchronizedSet(new HashSet<>());

    /**
     * 供外部获取当前所有按下的键
     * @return 一个包含当前所有被按下键的 keyCode 的 Set
     */
    public static Set<Integer> getPressedKeys() {
        return pressedKeys;
    }

    @Override
    public void keyTyped(KeyEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
        pressedKeys.add(e.getKeyCode());
    }

    @Override
    public void keyReleased(KeyEvent e) {
        pressedKeys.remove(e.getKeyCode());
    }
}
